package org.example.trigger.listener;

import lombok.extern.slf4j.Slf4j;
import org.example.domain.IDynamicThreadPoolService;
import org.example.domain.model.enity.ThreadPoolConfigEntity;
import org.example.registry.IRegistry;
import org.redisson.api.listener.MessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;

import java.util.List;


public class ThreadPoolConfigAdjustListener implements MessageListener<ThreadPoolConfigEntity> {
    private Logger logger =LoggerFactory.getLogger(ThreadPoolConfigAdjustListener.class);

    private final IDynamicThreadPoolService iDynamicThreadPoolService;

    private final IRegistry registry;

    public ThreadPoolConfigAdjustListener(IDynamicThreadPoolService iDynamicThreadPoolService, IRegistry registry) {
        this.iDynamicThreadPoolService = iDynamicThreadPoolService;
        this.registry = registry;
    }

    @Override
    public void onMessage(CharSequence charSequence, ThreadPoolConfigEntity threadPoolConfigEntity) {
        iDynamicThreadPoolService.updateThreadPoolConfig(threadPoolConfigEntity);
        List<ThreadPoolConfigEntity> threadPoolConfigEntities = iDynamicThreadPoolService.queryThreadPoolList();

        registry.reportThreadPool(threadPoolConfigEntities);
        registry.reportThreadPoolConfigParameter(threadPoolConfigEntity);

    }
}
